package escola.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import escola.modelo.Aluno;

@Stateless
public class AlunoDAOBean implements AlunoDAO {
	@PersistenceContext(unitName="matricula")
	private EntityManager em;
	
	@Override
	public void cadastrar(Aluno aluno) {
		em.persist(aluno);
	}

	@Override
	public Aluno recuperarPeloCPF(String cpf) {
		Query query = em.createNamedQuery("recuperaPorCPF", Aluno.class);
		query.setParameter("cpf", cpf);
		return (Aluno) query.getSingleResult();
	}

	@Override
	public Aluno recuperarPeloID(int id) {
		Query query = em.createNamedQuery("recuperaPorID", Aluno.class);
		query.setParameter("id", id);
		return (Aluno) query.getSingleResult();
	}

}
